import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import javax.jms.Message;
import javax.jms.TextMessage;

public class MyListener implements MessageListener
{
    int n = 0;
    double num = 0;
    double total = 0;

    public void onMessage(Message message)
    {
        try
        {
            ++n;
            num = Double.parseDouble(((TextMessage)message).getText());
            total += num;
            System.out.println("Received a message: " + num + " average: " + total/n);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

}
